home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / size / print68k.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-17  |  2.6 KB  |  93 lines

  1. /* 
  2.  * sun23Print.c --
  3.  *
  4.  *    Contains the machine specific routine for printing the size if the
  5.  *    machine is a sun2 or sun3 (they both have the same a.out format).
  6.  *
  7.  * Copyright 1989 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /a/newcmds/size/RCS/print68k.c,v 1.1 89/05/16 23:52:20 jhh Exp $ SPRITE (Berkeley)";
  19. #endif /* not lint */
  20.  
  21. #include <sun3.md/sys/exec.h>
  22. #include <sun3.md/a.out.h>
  23. #include "size.h"
  24.  
  25.  
  26. /*
  27.  *----------------------------------------------------------------------
  28.  *
  29.  * Print68k --
  30.  *
  31.  *    Prints out the size information for a sun2, sun3 or sun4 a.out file.
  32.  *
  33.  * Results:
  34.  *    SUCCESS if size information was printed, FAILURE otherwise.
  35.  *
  36.  * Side effects:
  37.  *    Stuff is printed.
  38.  *
  39.  *----------------------------------------------------------------------
  40.  */
  41.  
  42. ReturnStatus
  43. Print68k(fp, printName, fileName, printHeadings, bufferSize, buffer)
  44.     FILE    *fp;        /* file that header was read from */
  45.     Boolean    printName;    /* TRUE => print name of file */
  46.     char    *fileName;    /* name of file */
  47.     Boolean    printHeadings;    /* TRUE => print column headings */
  48.     int        bufferSize;    /* size of buffer */
  49.     char    *buffer;    /* buffer containing header */
  50. {
  51.  
  52.     struct exec        *header;
  53.     char        swappedHeader[sizeof(*header) * 2];
  54.     int            swappedSize = sizeof(swappedHeader);
  55.     int            status;
  56.  
  57.     if (bufferSize < sizeof(struct exec)) {
  58.     return FAILURE;
  59.     }
  60.     header = (struct exec *) buffer;
  61.     if (!N_BADMAG(*header)) {
  62.     goto doPrint;
  63.     }
  64.     if (FMT_68K_FORMAT != hostFmt) {
  65.     status = Fmt_Convert("{h2w7}", FMT_68K_FORMAT, &bufferSize, buffer,
  66.             hostFmt, &swappedSize, swappedHeader);
  67.     if (status) {
  68.         fprintf(stderr, "Fmt_Convert returned %d.\n", status);
  69.         return FAILURE;
  70.     }
  71.     header = (struct exec *) swappedHeader;
  72.     if (!N_BADMAG(*header)) {
  73.         goto doPrint;
  74.     }
  75.     }
  76.     return FAILURE;
  77. doPrint:
  78.     if (printHeadings) {
  79.     printf("%-7s %-7s %-7s %-7s %-7s\n", 
  80.            "text", "data", "bss", "dec", "hex");
  81.     }
  82.     printf("%-7d %-7d %-7d %-7d %-7x",
  83.            header->a_text, header->a_data, header->a_bss,
  84.            header->a_text + header->a_data + header->a_bss,
  85.            header->a_text + header->a_data + header->a_bss);
  86.     if (printName) {
  87.     printf("\t%s\n", fileName);
  88.     } else {
  89.     printf("\n");
  90.     }
  91.     return SUCCESS;
  92. }
  93.